package YAVMM::Log::Dispatch::Config;
use Moose;

extends 'Log::Dispatch::Configurator';
with 'MooseX::Object::Pluggable';

use YAVMM::Error;

has 'settings' => (
    is         => 'rw',
    does       => 'YAVMM::Settings',
    required   => 1,
);

# http://search.cpan.org/~drolsky/Moose-1.13/lib/Moose/Cookbook/Basics/Recipe11.pod
sub new {
    my $class = shift;

    my $obj = $class->SUPER::new(@_);

    return $class->meta->new_object(
	__INSTANCE__ => $obj,
	@_,
    );
}

# See http://search.cpan.org/~miyagawa/Log-Dispatch-Config-1.03/lib/Log/Dispatch/Config.pm
sub get_attrs_global {
    my $self = shift;

    my $dispatchers = $self->settings->get('cluster', 'log dispatchers') || 'Syslog';

    my @dispatchers = map { ucfirst lc $_  } split ' ', $dispatchers;

    @dispatchers = ('Syslog') if not @dispatchers;

    $self->load_plugins(@dispatchers);

    return {
	format      => undef,
	dispatchers => [ @dispatchers ],
    };
}

sub get_attrs {
    my $self = shift;
    my $name = shift;

    my $attrs = 'get_'.lc($name).'_attrs';

    if (defined $name and $self->can($attrs)) {
	return $self->$attrs;
    }
    else {
	die YAVMM::Error->new(error => "Invalid dispatcher name: $name");
    }
}

sub needs_reload { 1 }

sub reload {
    my $self = shift;
}

__PACKAGE__->meta->make_immutable(inline_constructor => 0);
1;

__END__

=head1 NAME

YAVMM::Log::Dispatch::Config -

=head1 SEE ALSO

L<Log::Dispatch::Config>
